function addBlogKind(o){
	createbackground();
	var addNewDiv = document.getElementById("maincontent");
	var position = getElementPositon(o);
	var fenLeiDiv = document.createElement("div"); 
	fenLeiDiv.setAttribute("id","feileidiv");
	var leftP = position.x-0;
	var topP = position.y-0;
	fenLeiDiv.style.cssText = "display:none;z-index:1001;position:absolute;left:"+leftP+"px;top:"+topP+"px;width:498px";
	fenLeiDiv.innerHTML = "<div id='mainAddFenLei'><div id='mainAddFenLeitop' onmousedown=\"getDragElement('feileidiv')\"><span id='mainAddFenLeitopText'>新增分类</span><img src='style/close.jpg' class='closejpg' onclick='closeBlogFeiLeiDiv(\"feileidiv\")' onmouseover='closeOverStyle(this)' onmouseout='closeOutStyle(this)' /></div><div id='mainAddFenLeibody'>分类名称：<input type='text' name='newFeiLei' id='newFeiLei' class='loginuserzhanghao8' onfocus=\"setMouseOnfouseStyle(\'newFeiLei\')\" onblur=\"setMouseOnblurStyle(\'newFeiLei\')\" /><br /><input type='button' value='确定' class='addFeiLeiButton' onclick='addNewBlogClass()' /><input type='button' value='取消' class='addFeiLeiButton' onclick='closeBlogFeiLeiDiv(\"feileidiv\")' /></div></div><div id='leftAddFenLei'></div><div id='bottomAddFenLei'></div>";
	addNewDiv.appendChild(fenLeiDiv);
	//$("#feileidiv").fadeIn("slow");
	$("#feileidiv").animate({height:'toggle'},"1000");
	//$("#feileidiv").animate({height:'100px',width:"100px"},"1000");
	//$("#feileidiv").animate({height:'200px',width:"200px"},"1000");
	//$("#feileidiv").fadeIn("slow");
	
}
function closeBlogFeiLeiDiv(ElementId){
	var parentDivNode = document.getElementById("maincontent");
	var addFeiLeidiv = document.getElementById(ElementId);
	parentDivNode.removeChild(addFeiLeidiv);
	var bg = document.getElementById("bgchop");
	document.body.removeChild(bg);
}
var xmlHttp;
var blogIds;
function blogDelete(blogId){
	var handle = confirm("删除后不能恢复，确定删除吗？");
	if(handle){
		blogIds = blogId;
	 	xmlHttp = createAjaxClass();
		var paras = "blogId="+blogId;
		var url="blogDelete.php?blogId="+blogId;
		xmlHttp.open("GET",url,true);
		xmlHttp.onreadystatechange=blogDeleteprocess;
		xmlHttp.send(null);
		
	}
	else{
		//alert("quexiaola");
		return false;
	}
}
function blogDeleteprocess(){
	if(xmlHttp.readyState == 4 && xmlHttp.status == 200){
		var processResult = xmlHttp.responseXML;
		var xmlElement = processResult.documentElement;
		var response = xmlElement.firstChild.data;
		if(response=="ok"){
			var blogFullId = "blogId"+blogIds;
			var blogIterm = document.getElementById(blogFullId);
			var parentBlog = blogIterm.parentNode;
			var htmlData ="<h3 style='color:#F580CE;margin-left:5px;'>删除成功！</h3>";
			blogIterm.innerHTML = htmlData;
			setTimeout("deleteNewDmes()",3000);
			//parentBlog.removeChild(blogIterm);
		}
		else if(response=="failed"){
			alert("删除失败！");
		}
		else{
			alert("错误操作！");
		}
	}	
}
function deleteNewDmes(){
	var blogFullId = "blogId"+blogIds;
	var blogIterm = document.getElementById(blogFullId);
	var parentBlog = blogIterm.parentNode;
	parentBlog.removeChild(blogIterm);
	
	
}
var blogNewKindAjax;
var blogNewKind;
function addNewBlogClass(){
 	blogNewKind = document.getElementById("newFeiLei").value;
	blogNewKindAjax = createAjaxClass();
	var paras = "blogKind="+blogNewKind;
	var url ="blogNewKindAdd.php";
	blogNewKindAjax.open("POST",url,true);
	blogNewKindAjax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	blogNewKindAjax.onreadystatechange=blogKindAdd;
	blogNewKindAjax.send(paras);
}
function blogKindAdd(){
	if(blogNewKindAjax.readyState==4 && blogNewKindAjax.status == 200){
		var xmlResponse = blogNewKindAjax.responseXML;
		var xmlRoot = xmlResponse.documentElement;
		var proccessData = xmlRoot.firstChild.firstChild.data;
		if(proccessData=="该类别已经存在"){
			alert(blogNewKind+"类别已经存在！");
		}
		else if(proccessData=="success"){
			var kindId = xmlRoot.lastChild.firstChild.data;
			
			var onptions = document.getElementById("blogKindSelect");
			
			var newOption = document.createElement("option");
			var textNode = document.createTextNode(blogNewKind);
			newOption.appendChild(textNode);
			newOption.setAttribute("value",kindId);
			newOption.setAttribute("selected",true);
			onptions.appendChild(newOption);
			closeBlogFeiLeiDiv("feileidiv");
		}
		else if(proccessData=="kongblogkind"){
			alert("请输入类名！");
		}
		else{
			alert("添加失败！");
		}
	}
	
}
function blogKindListFocus(o){
	o.style.cssText = "border:1px solid #AC77DB;padding-left:2px;width:100px;display:inline;"
	var spanBlock = o.previousSibling;
	o.value = spanBlock.firstChild.firstChild.data;
}
function blogKindListEditor(data,o){
	o.style.cssText="border:0px;width:50px;margin-left:5px;display:inline;";
	var kindSpan = o.previousSibling;
	var oldText = kindSpan.firstChild.data;
	var newKind = o.value;
	var kindManageAjax = createAjaxClass();
	var paras ="newKind="+newKind+"&m=0"+"&kindId="+data;
	var url ="blogKindManageAjax.php";
	kindManageAjax.open("POST",url,true);
	kindManageAjax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	kindManageAjax.onreadystatechange= function(){
	
		if(kindManageAjax.readyState== 4 && kindManageAjax.status == 200){
			var responseXml = kindManageAjax.responseXML;
			var xmlRootElement = responseXml.documentElement;
			var processData = xmlRootElement.firstChild.firstChild.data;
			if(processData=="updateOk"){
				kindSpan.firstChild.firstChild.data = newKind;
				var data="<p><img src='style/success-msg.png' alt='success' />更新成功!</p>";
				var css ="padding-top:50px;font-size:16px;";
				HHL.newAlertMes(data,css,'1000');
			}
			else if(processData=="updateFailed"){
				//kindSpan.firstChild.data = newKind;
				var data="<p><img src='style/error-msg.png' alt='error' />该类已经存在</p>";
				var css ="padding-top:20px;padding-left:20px;font-size:16px;";
				HHL.newAlertMes(data,css,'2000');
			}else{
				var data="<p><img src='style/error-msg.png' alt='error' />您输入的类别为空</p>";
				var css ="padding-top:20px;padding-left:30px;font-size:16px;";
				HHL.newAlertMes(data,css,'2000');
			}
			
		}
		
	}
	kindManageAjax.send(paras);
	
	o.value="编辑";
	 
}
function removeBlogKindMes(divId){
	var divBlock = document.getElementById(divId);
	document.body.removeChild(divBlock);
}
function blogKindListDelete(ob,data){
	var deleteCon = confirm("删除该分类后，该类的文章将归类到默认类\n确定删除吗？");
	if(deleteCon){
		var kindManageAjax = createAjaxClass();
		var paras ="m=1&kindId="+data;
		var url ="blogKindManageAjax.php";
		kindManageAjax.open("POST",url,true);
		kindManageAjax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		kindManageAjax.onreadystatechange=function(){
			if(kindManageAjax.readyState== 4 && kindManageAjax.status == 200){
				var responseXml = kindManageAjax.responseXML;
				var xmlRootElement = responseXml.documentElement;
				var processData = xmlRootElement.firstChild.firstChild.data;
				if(processData=="success"){
					var parentLi = ob.parentNode;
					var parentul = parentLi.parentNode;
					parentul.removeChild(parentLi);
					var data="<p><img src='style/success-msg.png' alt='success' />删除成功！</p>";
					var css ="color:white;font-size:20px;padding-top:50px;";
					newAlertMes(data,css);
				}else{
					var data="<p>删除失败！</p>";
					var css ="color:red;font-size:20px;padding-top:50px;";
					newAlertMes(data,css);
				}
			}
		}
		kindManageAjax.send(paras);
		
		
	}
}
function newAlertMes(data,css){
	var handleDiv = document.getElementById("kindMessage001002");
	if(!handleDiv){
		var handleDiv = document.createElement("div");
		var x = document.body.scrollWidth;
		var y = window.screen.availHeight;
		var scrollY = document.body.scrollTop || document.documentElement.scrollTop;
		x=x/2;y=y/4+scrollY;
		var cssText ="z-index:5;filter:Alpha(Opacity='80');opacity:0.8;background:grey;color:white;padding-top:70px;padding-left:90px;font-size:16px;font-weight:bolder;position:absolute;width:200px;height:100px;left:"+x+"px;top:"+y+"px;"+css;
		handleDiv.setAttribute("style",cssText);
		handleDiv.setAttribute("id","kindMessage001002");
		document.body.appendChild(handleDiv);
	}
	//var data = document.createTextNode("更新成功");
	//handleDiv.appendChild(data);
	handleDiv.innerHTML=data;
	setTimeout("removeBlogKindMes('kindMessage001002')",2000);	
}
//var imgparth = new Array();
//var imgneedle=0;
//var reg = /&lt;img.*src=([&quot;|quot;]?.*[&quot;|quot;]?)\s.*&gt;/g;
//function getimgurls(content){
//	var reg = /&lt;img.*src=([&quot;|quot;]?.*[&quot;|quot;]?)\s.*&gt;/g;
//	 imgurls= reg.exec(content);
//	 if(imgurls.index<content.length){
//			imgparth[imgneedle]=imgurls[1].replace(/[&quot;|quot;|#39]/g,"");
//			alert(imgparth[imgneedle]);
//			imgneedle++;
//			getimgurls(content)
//	}
//}
//for(var j=0;j<imgparth.length;j++){
//		alert(imgparth[j]);
//}
	
$(document).ready(function(){
 $('#submmitBlogButton').click(function(){submmitBlogAjax()});
});
window.blogSubCheck = "";//防止多次提交同一内容
function submmitBlogAjax(){
	if(blogSubCheck==""){
	 blogSubCheck=1;//1表示已提交
	var postType = document.getElementById("postType").value;
	var blogId = document.getElementById("blogId").value;
	var title = document.getElementById("myblogtitle").value;
	var kind = document.getElementById("blogKindSelect").value;
	if(title==""){
		HHL.newAlertMes("请您输入标题！","","2000");
		blogSubCheck="";
		return false;

	}
	var oEditor = CKEDITOR.instances.editor1;
	content = oEditor.getData();
//	var reg = /^&lt;img.*src=.(.*).*&gt;&/g;
//	getimgurls(content);
//	return "";
	content = content.replace(/'/g,"&#39;");//字符转换,将单引号转换成实体/'
	content = content.replace(/&/g,"0opc6");//字符转换，将&转换成0opc6
	content = content.replace(/\+/g,"O0Dkbol9");//字符转换，将+转换成O0Dkbol9
	title = title.replace(/&/g,"0opc6");
	//alert(content);
	var quanxian = document.getElementsByName("quanxian");
	for(var i=0;i<quanxian.length;i++){
		var inputCheck = quanxian[i].checked;
		if(inputCheck){
			quanxian = quanxian[i].value;
			break;
		}else continue;
	}
	
	
	blogManageAjax = createAjaxClass();
	
	var url = "blogManageAjax.php";
	var paras = "title="+title+"&&kind="+kind+"&&editor1="+content+"&&quanxian="+quanxian+"&&postType="+postType+"&&blogId="+blogId;
	
	blogManageAjax.open("post",url,true);
	blogManageAjax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	blogManageAjax.onreadystatechange = function(){
		if (blogManageAjax.readyState == 1){
			window.TempMesId = HHL.newMes("<img src='config/images/loading.gif' alt='waiting...' />请稍等...");
		}
		if (blogManageAjax.readyState == 4 && blogManageAjax.status == 200) {
			var mes ="";
			var xmlDoc = blogManageAjax.responseXML;
			//alert(mes);
			xmlRoot = xmlDoc.documentElement;
			var mes = xmlRoot.firstChild.firstChild.data;
			
			if(mes=="addsuccess"){
			 	var blogId = xmlRoot.lastChild.firstChild.data;
			 	var data = "<img src='style/success-msg.png' alt='success' />写博客成功!";
			 	var css = "";
			 	//HHL.newAlertMes(data,css,"2000");
				$("#"+TempMesId).html(data);
				window.url = "bloglist.php?blogId="+blogId;
				setTimeout("HHL.jumpUrl(url)",2000);
			}
			else if(mes=="addfailed"){
				blogSubCheck="";
				var data = "写博客失败!";
			 	var css = "";
				HHL.newAlertMes(data,css,"2000");
			}
			else if(mes=="updatesuccess"){
				var blogId = xmlRoot.lastChild.firstChild.data;
			 	var data = "<img src='style/success-msg.png' alt='success' />更新博客成功!";
			 	var css = "";
				//HHL.newAlertMes(data,css,"2000");
				$("#"+TempMesId).html(data);
				window.url = "bloglist.php?blogId="+blogId;
				setTimeout("HHL.jumpUrl(url)",2000);
			}else{
				blogSubCheck="";
				var blogId = xmlRoot.lastChild.firstChild.data;
			 	var data = "更新博客失败!";
			 	var css = "";
				HHL.newAlertMes(data,css,"2000");
			}
		}
	}
	blogManageAjax.send(paras);	
	}	
}
//'
(function($){
$(document).ready(function(){
		$("#commentsubmit").click(postblogcomment);
		$("#commentreset").click(resetform);
	})
function postblogcomment(){
	var blogid = $("#commentblogid").val();
	var username = $("#commentusername").val();
	var usernumber = $("#commentusernumber").val();
	var parantid = $("#commentparentid").val();
	var replyto = $('#commentreplyto').val();
	var content = $("#commentcontent").val();
	//alert(content.length));
	if(content==""){HHL.newAlertMes("请填写评价内容","","2000");return null;}
	$.post("blogcommentajax.php",{"blogid":blogid,"username":username,"usernumber":usernumber,"parantid":parantid,"replyto":replyto,"content":content},function(data){
		var message = data.substr(0,4);
		HHL.newAlertMes(message,"","2000");
		$("#commentcontent").val("");
		var htmldata = data.substr(4);
		$("#blogcommentsdisplay").append(htmldata);
		resetform();
	})
}
window['deleteblogcomment'] = deleteblogcomment;
function deleteblogcomment(id){
	if(!confirm("您确定要这么做吗?")){
		return false;
	}
	$.post("blogcommentdelete.php",{"blogcommentid":id},function(data){
		var message = data.substr(0,4);
		HHL.newAlertMes(message,"","2000");
		$("#blogdeletebutton_"+id).parent().parent().remove();
		//ob.parent().parent().html("");
	})
}
window['replytosetform'] = replytosetform;
function replytosetform(replyto,parentid,name){
	$("#commentreplyto").val(replyto);
	$("#commentparentid").val(parentid);
	$("#commentcontent").focus();
	$("#replytohead").html("<h3>回复"+name+"</h3>");
}
function resetform(){
	$("#replytohead").html("");
	$("#commentcontent").val("");
	$("#commentparentid").val("");
	$("#commentreplyto").val("");
	$("#commentcontent").val("");
}
$(document).ready(function(){
	$(".blogkindconrolbutton").click(blogkindlistcontrolbartoggle);
	$("#setBlogDraft").click(addBlogDraft);
})
var blogKindControlBarHandle = false;
function blogkindlistcontrolbartoggle(){
	if(!blogKindControlBarHandle){
		blogkindlistcontrolbar();
		blogKindControlBarHandle = true;
	}else{
		hideblogkindlistcontrolbar();
		blogKindControlBarHandle = false;
	}
}
function blogkindlistcontrolbar(){
	$(".kindlisteditor").css({"display":"inline"});
	$(".blogDelteS").css({"display":"inline"});
}
function hideblogkindlistcontrolbar(){
	$(".kindlisteditor").css({"display":"none"});
	$(".blogDelteS").css({"display":"none"});
}

var handledraftId ="";
function addBlogDraft(){
		var title = $("#myblogtitle").val();
		var kind = $('#blogKindSelect').val();
		var oEditor = CKEDITOR.instances.editor1;
		var content = oEditor.getData();
		content = content.replace(/'/g,"&#39;");//字符转换,将单引号转换成实体/'
		content = content.replace(/&/g,"0opc6");//字符转换，将&转换成0opc6
		content = content.replace(/\+/g,"O0Dkbol9");//字符转换，将+转换成O0Dkbol9
		content = content.replace(/\//g,"O0Dkbol8");//字符转换，将+转换成O0Dkbol9
		var url = "blogManageAjax.php";
		var data = {'title':title,'kind':kind,'postType':2,'editor1':content,'draftId':handledraftId};
		var download = $.ajax({
			  type: 'POST',
			  url: url,
			  data: data,
			  beforeSend:function(){
			  	window.draftSaveTemp = HHL.newMes("<img src='config/images/loading.gif' alt='loading' />保存中...");
			  },
			  success: function(data){
			  	//HHL.newMes(data);
			  	//var draftid = data.documentElement.lastChild.firstChild.value;
			  	var draftid = data.documentElement.lastChild.firstChild.nodeValue;
				var num =  data.documentElement.childNodes[1].firstChild.nodeValue;
			  	$("#"+draftSaveTemp).remove();
				HHL.newAlertMes("<img src='style/success-msg.png' alt='success' />已保存草稿","width:200px;height:30px;padding-top:20px;background:white;color:green;border:0px;","1500");
			  	var blogdraftnum= $("#blogdraftnum");
			  	blogdraftnum.css({height:'0px',color:"red"});
			  	blogdraftnum.html(num);
			  	blogdraftnum.animate({height:"20px",'fontWeight':"bolder"},1000,
			  		function(){blogdraftnum.css({'color':"black"})});
			  	handledraftId = draftid;
			  },
			  error:function(XMLHttpRequest, textStatus, errorThrown){
			  	HHL.newAlertMes("error...");
			  } 
			});
}
window['addBlogDraft'] = addBlogDraft;

$(document).ready(function(){
	$("#blogdraftbox").click(readBlogDrafts);
})

function readBlogDrafts(){
	var positons = HHL.getPosition();
	var Theight = positons.Th;
	var Twidth = positons.Tw;
	var cssStr = "position: absolute; left: 0px; top: 0px; background-color: white; z-index: 4; filter:Alpha(Opacity='50');opacity: 0.5;display:block;height:"+Theight+"px;width:"+Twidth+"px;";
	var NewDiv = "<div id='wholemark'></div>";
	$("body").append(NewDiv);
	$("#wholemark").attr("style",cssStr);
	var url = 'blogDraftAjax.php';
	var data ={postType:"3"};
	
	$.ajax({
		type:"Post",
		url:url,
		data:data,
		beforeSend:function(){
			  	//HHL.newAlertMes("sending...");
		},
		success:function(data){
			window.blogDraftsListHandle = HHL.newMes(data,"width:600px;height:auto;left:400px;padding-top:20px;margin-bottom:20px;");
		}
	})

}

function loadBlogDraft(){
	
	var blogdrafts = $(".blogdraftradio:checked");
	var blogdraftId = blogdrafts.val();
	if(blogdraftId){
		var url = 'blogManageAjax.php';
		var data ={postType:"4",draftId:blogdraftId};
		$.ajax({
			type:"Post",
			url:url,
			data:data,
			beforeSend:function(){
				  	//HHL.newAlertMes("sending...");
					window.loadBlogDraftHandle = HHL.newAlertMes("<img src='config/images/loading.gif' alt='waiting...' />加载中...");
			},
			success:function(data){
				var title = data.documentElement.childNodes[0].firstChild.nodeValue;
				if(data.documentElement.childNodes[1].childNodes.length!=0){
					var kind = data.documentElement.childNodes[1].firstChild.nodeValue;
				}else{
					var kind ="";
				}
				var content="";
				var url = "blogDraftContent.php";
				var contentdata = {postType:7,draftId:blogdraftId};
				$.ajax({type:"Post",
						url:url,
						data:contentdata,
						success:function(data){
							$("#"+loadBlogDraftHandle).remove();
							content = data;
							var oEditor = CKEDITOR.instances.editor1;
							oEditor.setData(content);	
						}
				});
				$("#myblogtitle").val(title);				
				$('#'+blogDraftsListHandle).remove();				
				$('#wholemark').remove();
			}
		})
	}else{
		HHL.newAlertMes('请选择要加载的草稿！','padding-left:25px;','2000');
	}
}
window['loadBlogDraft'] = loadBlogDraft;

function deleteblogdraft(draftId){
	var check = confirm("确定删除吗？");
	if(!check){
		return false;
	}
	var url ='blogManageAjax.php';
	var data ={postType:"5",draftId:draftId};
	$.ajax({
			type:"Post",
			url:url,
			data:data,
			success:function(data){
				var handle = data.documentElement.firstChild.firstChild.nodeValue;
				if(handle){
					HHL.newAlertMes("<img src='style/success-msg.png' alt='success' />删除成功","","2000");
					$("#blogdraftitermsload"+draftId).remove();
				}else{
					HHL.newAlertMes("删除失败","","2000");
				}
			}
	})
}
window['deleteblogdraft'] = deleteblogdraft;

function closeBlogDraft(ob){
	$("#wholemark").remove();
	var parent = ob.parentNode.parentNode.parentNode;
	var targetDiv = ob.parentNode.parentNode
	parent.removeChild(targetDiv);
 
}
window['closeBlogDraft']= closeBlogDraft;

})(jQuery)


